package com.itheima.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 王磊
 * @date 2022/5/11
 */
@Component
@RestControllerAdvice(basePackageClasses = RestController.class)
@ResponseBody
@Slf4j
public class MyExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R<String> doException(Exception e){
        log.info(e.getMessage());
        return R.error("未知异常");
    }

}
